package org.example.exception;

import org.example.pojo.R;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author TonySong
 * @date 2024/7/10 0010
 * @time 16:10
 */
@RestControllerAdvice
public class MyException {

    @ExceptionHandler(value = ArithmeticException.class)
    public R handle(ArithmeticException e) {
        return R.error(501,"对不起，服务器发生了算术异常");
    }

    @ExceptionHandler(NullPointerException.class)
    public R nullHandler(NullPointerException e){
        return R.error(501,"空指针异常！");
    }

    @ExceptionHandler(Exception.class)
    public R exceptionHandler(Exception e){
        return R.error(501,"服务器错误！");
    }
}
